<?php
defined('_JEXEC') or die;

class ModDoskaFilterHelper {
	
	public static function getListCategory() {
		$db  = JFactory::getDbo();
		$query = $db->getQuery(TRUE);
		
		$query->select('id, name, parentid');
		$query->from('#__doska_categories');
		$query->where('state = 1');
		
		$db->setQuery($query);
		
		try {
			$rows = $db->loadObjectList();
		}
		catch(RuntimeException $e) {
	JFactory::getApplication()->enqueueMessage($e->getMessage(),'error');
			return false;
		}
		
		$arr = array();
		
		if(is_array($rows)) {
			foreach($rows as $row) {
				if(!$row->parentid) {
					$arr[$row->id][] = $row->name;
				}
				else {
					$arr[$row->parentid]['next'][] = array(
															'id'=>$row->id,
															'name'=>$row->name
															);
				}
			}
		}
		
		return $arr;
	}
	
	public static function getListType() {
		
		$db = JFactory::getDbo();
		$query = $db->getQuery(TRUE);
		
		
		$query->select('id, name');
		$query->from('#__doska_types');
		
		$query->where('state = 1');
		
		$db->setQuery($query);
		
		try {
			$rows = $db->loadObjectList();
		}
		catch(RuntimeException $e) {
			JFactory::getApplication()->enqueueMessage($e->getMessage(),'error');
			return false;
		}
		
		
		
		return $rows;
	}
	
}
?>